package com.xindaoapp.happypet.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

import com.xindaoapp.happypet.R;

public class FilterPopupWindow extends PopupWindow {


    private final Button btn_new;// 最新
    private final Button btn_hot;// 最热

    public FilterPopupWindow(Context context, OnClickListener itemsOnClick) {
        super(context);
        final View club_list_layout = View.inflate(context, R.layout.club_list_layout, null);
        btn_new = (Button) club_list_layout.findViewById(R.id.btn_new);
        btn_hot = (Button) club_list_layout.findViewById(R.id.btn_hot);
        // 设置按钮监听
        btn_new.setOnClickListener(itemsOnClick);
        btn_hot.setOnClickListener(itemsOnClick);

        this.setContentView(club_list_layout);


        this.setWidth(LayoutParams.MATCH_PARENT);
        // 设置FilterPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.MATCH_PARENT);
        // 设置FilterPopupWindow弹出窗体可点击
        this.setFocusable(true);
        // 设置FilterPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.PopupDownAnimation);
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置FilterPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        // club_list_layout添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        club_list_layout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int height = club_list_layout.findViewById(R.id.pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
    }



}
